package 牛客_面试必刷.Month07.day12;

public class 数组中出现次数超过一半的数字 {
    public int MoreThanHalfNum_Solution(int [] array) {
        int count = 0;
        int res = 0;
        for (int i = 0; i < array.length; i++) {
            if(count == 0){
                res = array[i];
                count++;
            }else if(res != array[i]){
                count--;
            }else{
                count++;
            }
        }
        return res;
    }
}
